/*
Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors is 2500 which is 50 * 50, a square!

Given two integers m, n (1 <= m <= n) we want to find all integers between m and n whose sum of squared divisors is itself a square. 42 is such a number.

The result will be an array of arrays(in C an array of Pair), each subarray having two elements, first the number whose squared divisors is a square and then the sum of the squared divisors.

#Examples:

list_squared(1, 250) --> [[1, 1], [42, 2500], [246, 84100]]
list_squared(42, 250) --> [[42, 2500], [246, 84100]]
The form of the examples may change according to the language, see Example Tests: for more details.
*/

function listSquared(m, n) {
    let result = [];
    for (let i = m; i <= n; i++) {
        let sum = 0;
        for (let j = 1; j <= i; j++) {
            if (i % j === 0) sum += j * j;
        }
        let sqrt = Math.sqrt(sum);
        if (sqrt === parseInt(sqrt)) {
            result.push([i, sum]);
        }

    }
    return result;
}

function listSquared(m, n) {
    let result = [];
    for (let i = m; i <= n; i++) {
        let sum = 0;
        for (let j = 1; j <= i / 2; j++) {
            if (i % j === 0) sum += j * j;
        }
        sum += i * i;
        if (Number.isInteger(Math.sqrt(sum))) {
            result.push([i, sum]);
        }
    }
    return result;
}

const getDivisors = num => {
    let arr = [];
    for (let j = 1; j <= Math.sqrt(num); j++) {
        if (num % j === 0) {
            arr.push(j);
            arr.push(num/j);
        };
    }
    return arr;
};

getDivisors(19647)